package cn.deschen.common.config.security;

import org.springframework.stereotype.Component;

/**
 * @Author hanbin_chen
 * @Description 用户登录上下文
 * @DateTime 2021/6/3
 * @Version V1.0.0
 */
@Component
public class UserInfoContext {

    private static final ThreadLocal<UserDetails> threadLocal = new ThreadLocal<>();

    /**
     * 添加当前用户
     * @return
     */
    public static void setCurrentUser(UserDetails user) {
        threadLocal.set(user);
    }

    /**
     * 获取当前用户
     * @return
     */
    public static UserDetails getCurrentUser() {
        return threadLocal.get();
    }

    /**
     * 移除当前用户
     */
    public static void removeCurrentUser() {
        threadLocal.remove();
    }

}
